In an object-oriented programming language, mathematical values and other literal data types are typically represented as objects. A literal is a value that is expressed as itself rather than as a variable's value or the result of an expression. For example, the number 5 is a literal of primitive data type Integer in the Java™ object-oriented programming language. Other primitive data types in the Java programming language include Boolean, Character, Byte, Short, Long, Float, and Double. Each of the primitive data types has a class wrapper around it that is useful when needed to manipulate literal types as objects. Accordingly, in the example above, the number 5 is an object of class Integer. The aforementioned classes are also immutable, which means that objects of these classes are not subject to changing fields. Therefore, the fields of the object 5 cannot be changed. The Java programming language also includes String as an immutable type, although it is not a primitive data type.
The identity of an object can often be detected in a variety of ways in object-oriented languages. For example, many object-oriented languages include an identity method that is implemented using an operator such as the “=” operator. The “=” operator determines whether two variables are identified with the same object. Another manner in which the identity of objects may be determined is by changing the fields of the objects. Field changing, however, is ineffective to determine the identity of objects when the objects are immutable.
Yet another method of determining the identity of objects exists in some object-oriented programming languages that enable multithreading, such as the Java programming language. Multithreaded languages provide support for multiple threads of execution, each handling a different task. The Java programming language, for example, may determine the identity of objects using the synchronized instruction. In particular, when a thread executes the synchronized statement to acquire an exclusive lock for an object, it does not access the object until it can obtain this lock, ensuring that no other threads can access the object at the same time. If a particular thread uses the synchronized statement to attempt to use one variable of an object, it can determine whether or not the object is locked. If the object is locked, then the variable is from the same object as another variable in use by another thread. If the object is not locked, then it can be determined that the variable in use by the other thread is not from the same object. The identity of the object, therefore, is determinable through use of the synchronized operation.